<template>
  <!--
      	作者：luoyiming
      	时间：2020-06-01
      	描述：审核
      -->
  <div v-if="status == 10">
    <el-dialog
      title="摊位审核"
      width="600px"
      :visible.sync="dialogVisible"
      @close="dialogFormVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form :model="form">
        <el-form-item label="审核状态" :label-width="formLabelWidth">
          <div>
            <el-radio v-model="audit" label="20">通过</el-radio>
            <el-radio v-model="audit" label="30">不通过</el-radio>
          </div>
        </el-form-item>
        <div v-if="audit == 30">
          <el-form-item label="不通过原因" :label-width="formLabelWidth">
            <el-input
              v-model="form.reject_reason"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible">取 消</el-button>
        <el-button type="primary" @click="auditSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>

  <div v-else>
    <el-dialog
      title="不通过原因"
      width="600px"
      :visible.sync="dialogVisible"
      @close="dialogFormVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <p>{{ reject_reason }}</p>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisible">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import StallApi from "@/api/stall.js";

export default {
  data() {
    return {
      status: "",
      apply_status: "",
      audit: "",
      reject_reason: "",
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      dialogVisible: false
    };
  },
  props: ["open", "form"],
  watch: {
    open: function(n, o) {
      this.dialogVisible = this.open;
      if (n != o && n) {
        this.status = this.form.apply_status.value;
        this.audit = this.form.apply_status.value;
        if (this.audit == 30) {
          this.reject_reason = this.form.reject_reason;
        }
      }
    }
  },
  created() {},
  methods: {
    /*审核*/
    auditSubmit() {
      let self = this;
      let params = this.form;
      StallApi.auditStall(
        {
          apply_id: params.apply_id,
          apply_status: this.audit,
          reject_reason: params.reject_reason
        },
        true
      )
        .then(data => {
          self.$message({
            message: "恭喜你，操作成功",
            type: "success"
          });
          self.dialogFormVisible(true);
        })
        .catch(error => {});
    },

    /*关闭弹窗*/
    dialogFormVisible(e) {
      this.$emit("close", e || false);
    }
  }
};
</script>

<style></style>
